package com.location.footprint.fragment

import android.content.Intent
import android.content.res.ColorStateList
import android.os.Bundle
import android.view.View
import android.widget.RelativeLayout
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.GridLayoutManager
import com.location.footprint.R
import com.location.footprint.activity.ThemeActivity
import com.location.footprint.adapter.MapBottomAdapter
import com.location.footprint.base.BaseAppAplication
import com.location.footprint.bean.MapBottomBean
import com.location.footprint.utils.LogUtil
import com.location.footprint.utils.Utils
import kotlinx.android.synthetic.main.fragment_user.*
import kotlinx.android.synthetic.main.layout_user_toolbar.*

class UserFragment : BaseFragment() {
    private var mTitle: String? = null

    companion object {

        fun getInstance(title: String): UserFragment {
            val userFragment = UserFragment()
            userFragment.mTitle = title
            return userFragment
        }
    }

//    companion object {
//        val instance: UserFragment by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
//            UserFragment()
//        }
//    }

    override fun getLayoutId(): Int {
        return R.layout.fragment_user
    }

    override fun initView() {
        LogUtil.e(mTitle)
    }

    override fun initData() {

    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val params = view_status.layoutParams as RelativeLayout.LayoutParams
        params.height = Utils.getStatusHeight(activity)
        view_status.layoutParams = params
        initItemData()

    }

    fun initItemData() {
        var arrayList = arrayListOf(MapBottomBean("我的踩点", R.mipmap.ic_user_footprint)
                , MapBottomBean("我的留言", R.mipmap.ic_user_comments)
                , MapBottomBean("我的回复", R.mipmap.ic_user_reply)
                , MapBottomBean("我的赞", R.mipmap.ic_user_like)
                , MapBottomBean("我的寻物", R.mipmap.ic_user_find)
                , MapBottomBean("寻求帮助", R.mipmap.ic_user_help)
                , MapBottomBean("主题风格", R.mipmap.ic_user_theme)
        )

        val mAdapter = MapBottomAdapter()
        recyclerview.layoutManager = GridLayoutManager(getContext(), 4, GridLayoutManager.VERTICAL, false)
        recyclerview.adapter = mAdapter
        mAdapter.setNewData(arrayList)
        mAdapter.setOnItemClickListener { adapter, view, position ->
            when (position) {
                0 -> ""
                1 -> ""
                2 -> ""
                3 -> ""
                4 -> ""
                5 -> ""
                6 -> startActivity(Intent(activity, ThemeActivity::class.java))


            }
        }
    }

    fun setTheme(theme: Int) {
        if (theme == R.color.black) {
            relative_user.background = ContextCompat.getDrawable(context!!, R.color.white)
            img_user_setting.backgroundTintList = null
            img_user_message.backgroundTintList = null
            text_search.setTextColor(ContextCompat.getColor(context!!, R.color.text_cancel))
            text_search.background=ContextCompat.getDrawable(context!!, R.drawable.share_user_search)
        } else {
            relative_user.background = ContextCompat.getDrawable(context!!, theme)
            img_user_setting.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(context!!, R.color.white))
            img_user_message.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(context!!, R.color.white))
            text_search.setTextColor(ContextCompat.getColor(context!!, R.color.white))
            text_search.background=ContextCompat.getDrawable(context!!, R.drawable.share_user_search_color)
        }

    }

    override fun onResume() {
        super.onResume()
        setTheme(BaseAppAplication.theme)
    }

}